-
Notifications
You must be signed in to change notification settings - Fork 263
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
content: Support the new class of channel wildcard mentions #1073
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks! This looks good. Left some comments.
lib/model/content.dart
Outdated
const mentionClass = r"user(?:-group)?-mention|" | ||
"(?:user-mention channel-wildcard-mention)"; | ||
return RegExp("^(?:$mentionClass)(?: silent)?|silent (?:$mentionClass)\$"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like the non-capturing groups added here are not necessary:
const mentionClass = r"user(?:-group)?-mention|" | |
"(?:user-mention channel-wildcard-mention)"; | |
return RegExp("^(?:$mentionClass)(?: silent)?|silent (?:$mentionClass)\$"); | |
const mentionClass = r"user(?:-group)?-mention|" | |
"user-mention channel-wildcard-mention"; | |
return RegExp("^(?:$mentionClass)(?: silent)?|silent $mentionClass\$"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seeing this I wondered if regular expressions are the right tool for this issue, but then I read from the commit message of 4a10b3c mentioning that this is more efficient than classes
. Makes sense.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The groups around mentionClass
are needed. The revised version above would have a three-way alternative: either ^(?:$mentionClass)(?: silent)?
, or silent user(?:-group)?-mention
, or user-mention channel-wildcard-mention$
.
Probably the cleanest way to express that is by mentionClass
itself containing the (?:
and )
.
In main there's also a group enclosing everything between ^
and $
. That's necessary so that ^
and $
apply to all alternatives, instead of just the first and last of them respectively.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've just sent #1086 to refactor the existing logic here, reducing the role of the regexp and hopefully making it easier to add more features. @sm-sayedi PTAL and try rebasing your work atop that.
20c3911
to
79b117d
Compare
lib/model/content.dart
Outdated
bool isChannelWildcardClassIncluded = false; | ||
if (classes[i] == 'channel-wildcard-mention') { | ||
// A newly-added class for channel wildcard mentions. | ||
// See: https://github.com/zulip/zulip/pull/31075 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The example is contained in our tests, so we can probably cut this comment. And the context of "newly-added" might fit better in the commit message.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(On what goes in a commit message vs. a comment, see: https://github.com/zulip/zulip-mobile/blob/main/docs/style.md#commit-messages-vs-comments )
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @sm-sayedi for taking care of this, and @PIG208 for the previous reviews! This all looks good; some nits below.
lib/model/content.dart
Outdated
int i = 0; | ||
|
||
if (i >= classes.length) return null; | ||
bool isChannelWildcardClassIncluded = false; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: can simplify "is X included" to "has X":
bool isChannelWildcardClassIncluded = false; | |
bool hasChannelWildcardClass = false; |
lib/model/content.dart
Outdated
if (classes[i] == 'channel-wildcard-mention') { | ||
// A newly-added class for channel wildcard mentions. | ||
// See: https://github.com/zulip/zulip/pull/31075 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think a comment is useful here, because there is certain information it can convey that's relevant for the reader trying to understand this function. Here's a version focused on that information:
if (classes[i] == 'channel-wildcard-mention') { | |
// A newly-added class for channel wildcard mentions. | |
// See: https://github.com/zulip/zulip/pull/31075 | |
if (classes[i] == 'channel-wildcard-mention') { | |
// Newer channel wildcard mentions have this class; older ones don't. |
In particular, in my other review comment above I almost suggested naming the variable isChannelWildcard
— before I remembered that that would be an inaccurate name, because some genuine channel wildcards don't have this class. That fact will be highly relevant when someone goes to implement #646, as it'd otherwise be tempting to use this class for doing so.
lib/model/content.dart
Outdated
if (classes[i] == 'user-mention' || | ||
(classes[i] == 'user-group-mention' && !isChannelWildcardClassIncluded)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: indentation; and operators go after newline:
if (classes[i] == 'user-mention' || | |
(classes[i] == 'user-group-mention' && !isChannelWildcardClassIncluded)) { | |
if (classes[i] == 'user-mention' | |
|| (classes[i] == 'user-group-mention' && !isChannelWildcardClassIncluded)) { |
(See examples in parseInlineContent
below.)
With less indentation, the second sub-condition looks like it's a peer of the if
condition as a whole.
For the rationale for ||
after newline, see:
https://github.com/zulip/zulip-mobile/blob/a115df1f71c9dc31e9b41060a8d57b51c017d786/tools/formatting.eslintrc.yaml#L20-L23
@@ -1213,7 +1255,13 @@ void main() { | |||
testParseExample(ContentExample.groupMentionSilent); | |||
testParseExample(ContentExample.groupMentionSilentClassOrderReversed); | |||
|
|||
// TODO test wildcard mentions |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Cool, good to have this handled 🙂
'<p><span class="silent user-mention channel-wildcard-mention" data-user-id="*">channel</span></p>', | ||
const UserMentionNode(nodes: [TextNode('channel')])); | ||
|
||
static final legacyChannelWildcardMentionPlain = ContentExample.inline( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, this naming is good: the current/new way gets the simple name, and the old way gets the longer "legacy" name.
79b117d
to
9c3d023
Compare
29e0154
to
698a93b
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the revision! Looks good, with one nit below. I'll fix that and merge.
lib/model/content.dart
Outdated
// A silent @-mention. We ignore this flag; see [UserMentionNode]. | ||
// A silent @-mention. We ignore this flag; see [UserMentionNode]. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: extraneous change
For channel wildcard mentions, the class in the corresponding HTML used to be the same as the user mentions (class="user-mention"), but now there's an additional class added. Now it looks like the following: class="user-mention channel-wildcard-mention". Fixes: zulip#1064
698a93b
to
fb6291f
Compare
For channel wildcard mentions, the class in the corresponding HTML used to be the same as the user mentions (
class="user-mention"
), but now there's an additional class added. Now it looks like the following:class="user-mention channel-wildcard-mention"
.Fixes: #1064